<?php
// 获得用户信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");

$select = "SELECT * FROM user_infos";

if(isset($_GET['userID'])){
    $userID = $_GET['userID'];
    $select = "SELECT * FROM user_infos WHERE user_ID LIKE '%".$userID."%'";
}

$result = mysqli_query($connect_DB, $select);

if($result){
    echo"<p>当前共有".mysqli_num_rows($result)."条用户信息</p>";
    if(mysqli_num_rows($result) > 0){
        echo"
        <div class='tab-div'>
        <table class='table'>
            <thead>
                <tr>
                    <th scope='col'>用户ID</th>
                    <th scope='col'>用户昵称</th>
                    <th scope='col'>联系电话</th>
                    <th scope='col'>登记宠物数量</th>
                    <th scope='col'>操作</th>
                </tr>
            </thead>
            <tbody>";
        while($row = mysqli_fetch_object($result)){
            $select_pet = "SELECT * FROM pet_infos WHERE user_ID = '".$row->user_ID."'";
            $count = mysqli_num_rows(mysqli_query($connect_DB, $select_pet));
            echo"<tr>
                    <th scope='row'>".$row->user_ID."</th>
                    <td>".$row->user_Name."</td>
                    <td>".$row->user_Phone."</td>
                    <td>".$count."</td>
                    <td><a href='admin_ControlUserInfo.php?userID=".$row->user_ID."'>查看详情</a></td>
                </tr>";
        }
        echo"</tbody> </table> </div>";
    }else{
        echo"<div class='tab-div'><p class='none'>未查询到信息</p></div>";
    }
}
else{
    echo"<div class='tab-div'><p class='none'>查询出错<br/>".$select."</p></div>";
}

$connect_DB->close();
?>